import request from '../util/request'

export function loginByUsername(username, password) {
    const data = {
        loginName: username,
        password: password
    }
    return request({
        url: '/user/login',
        method: 'post',
        data
    })
}

export function addCotolog(name, projectId, parentId) {
    return request({
        url: "/catalog",
        method: "post",
        data: {
            name: name,
            projectId: projectId,
            parentId: parentId
        }
    });
}


export function delCotolog(catalogId, projectId) {
    return request({
        url: "/catalog/del/" + projectId + "/" + catalogId,
        method: "get",
    });
}


export function addProject(project) {
    return request({
        url: "/project",
        method: "post",
        data: project
    });
}


export function getProjectById(projectId) {
    return request({
        url: "/project/get/"+projectId,
        method: "get"
    });
}

export function listUserByProjectId(projectId) {
    return request({
        url: "/project/user/"+projectId,
        method: "get"
    });
}


export function addUserProject(projectId,nickname,power) {
    return request({
        url: "/project/user",
        method: "post",
        data:{
            projectId,
            nickname,
            power
        }
    });
}

export function delUserProject(upId) {
    return request({
        url: "/project/user/del/"+upId,
        method: "get"
    });
}

export function delProject(projectId) {
    return request({
        url: "/project/del/"+projectId,
        method: "get"
    });
}


export function checkNickname(nickname) {
    return request({
        url: "/user/check",
        method: "post", 
        data:{
            nickname
        }
    });
}

export function checkEmail(email) {
    return request({
        url: "/user/check",
        method: "post", 
        data:{
            email
        }
    });
}


export function register(nickname,email, password) {
    const data = {
        nickname: nickname,
        loginName: email,
        password: password
    }
    return request({
        url: '/user/register',
        method: 'post',
        data
    })
}

export function activeUser(token) {
    return request({
        url: "/user/active/"+token,
        method: "get"
    });
}